NSString
宣告方式
1 2
| NSString *str1 = @"Log : 123"; NSString *str2 = [NSString stringWithFormat:@"Log : %d",456];
|
NSNumber
宣告方式
1 2 3 4
| NSNumber *number1 = @1; NSNumber *number2 = @2.2; NSNumber *number3 = @(-1); NSNumber *number4 = @(10*1.1);
|
NSNumber to 基本型態
1 2 3
| number1.intValue; number1.floatValue;
|
NSArray
宣告方式
1 2
| NSArray *array1 = @[@1,@2,@3]; NSArray *array2 = @[];
|
使用方法
1 2 3 4 5 6 7
| array1[0];
array1.firstObject; array2.firstObject;
array1.lastObject; array2.lastObject;
|
NSDictionary
宣告方式
1 2
| NSDictionary *dict = @{@"Yume":@1, @"Dream":@2};
|
使用方法
1 2
| dict[@"Yume"]; dict[@"Dream"];
|
Mutable VS Non Mutable
Non Mutable
Non Mutable型態的變數無法再新增,修改,刪除
Non Mutable to Mutable
1 2
| [array1 mutableCopy]; [dict mutableCopy];
|